<template>
	<view>
		<view class="detail-bottom">
			<view class="detail-bottom_icons-input" @click="openComment">
				<text>发出你的评论</text>
				<uni-icons type="compose" size="16" color="#F07373"></uni-icons>
			</view>
			<view class="detail-bottom_icons">
				<view class="detail-bottom_icons-box" @click="open">
					<uni-icons type="chat" size="22" color="#F07373"></uni-icons>
				</view>
				<view class="detail-bottom_icons-box" @click="likeTap(formData._id)">
					<!-- <uni-icons :type="formData.is_like? 'heart-filled':'heart' "  size="22" color="#F07373" ></uni-icons> -->
					<uni-icons :type="formData.is_like? 'heart-filled':'heart' "  size="22" color="#F07373"></uni-icons>
				</view>
				<view class="detail-bottom_icons-box" @click="thumbsup(formData._id)">
					<uni-icons :type="formData.is_thumbs_up?'hand-thumbsup-filled': 'hand-thumbsup'  " size="22" color="#F07373"></uni-icons>
				</view>
			</view>
		</view>
		
		<!-- 评论发布模块 -->
		<popup ref="popup" @getComments="getComments" @UpdateComment="UpdateComment"></popup>
	</view>
</template>

<script>
	export default {
		props:{
			jump:{
				type:String,
				default(){
					return ''
				}
			},
			formData:{
				type:Object,
				default(){
					return {}
				}
			}
		},
		created() {
			console.log("this.jump",this.jump)
			console.log("this.formData",this.formData)
		},
		data() {
			return {
				commentsValue:'',
			};
		},
		computed:{
			//监听this.formData.is_like 或使用watch
			
		},
		watch:{
			
		},
		methods:{
			
			//发布
			UpdateComment(commentsValue){
				console.log("发布1")
				this.$emit("UpdateComment",commentsValue)
				
			},
			//点赞
			thumbsup(article_id){
				this.setUpdateThumbs(article_id)
			},
			//收藏文章
			likeTap(article_id){
				console.log("收藏文章")
				this.setUpdateLike(article_id)
				// this.$store.dispatch()
			},
			//打开评论列表
			open(){
				console.log('评论列表')
				uni.navigateTo({
					url:"../detail-comments/detail-comments?id="+this.formData._id
				})
			},
			//关闭评论发布窗口
			closeComment(){
				this.$refs.popup.closeComment()
			},
			//打开评论发布窗口
			openComment(){
				console.log("发布窗口")
				this.$refs.popup.openComment()
			},
			//收藏文章
			setUpdateLike(article_id){
				uni.showLoading()
				this.$api.update_like({
					article_id
				}).then(res=>{
					uni.hideLoading()
				    
					//Tost 提示状态判断
					this.formData.is_like = !this.formData.is_like
					console.log('this.formData.is_like:',this.formData.is_like)
					uni.$emit("update_article","follow")
					uni.showToast({
						title:this.formData.is_like?'收藏成功':'取消收藏',
						icon:"none"
					})
					console.log("收藏成功")
					// uni.navigateTo({
					// 	url:"/pages/Jump-around/Jump-around?jump="+this.jump
					// })
				})
			},
			//文章点赞
			setUpdateThumbs(article_id){
				uni.showLoading();
				this.$api.update_thumbsup({
					article_id
				}).then(res=>{
					// console.log(res)
					uni.hideLoading()
					this.formData.is_thumbs_up = true
					console.log(res.data)
					this.formData.thumbs_up_count = res.data
					// console.log(this.formData.thumbs_up_count)
					// this.$forceUpdate();
					uni.showToast({
						title:res.message,
					    icon:"none"
					})
					
				})
			},
			//触发页面重新获取评论数据
			getComments(){
				this.$emit("getComments")
			},
		}
	}
</script>

<style lang="scss">
	.detail-bottom{
		position: fixed;
		bottom:0;
		left:0;
		display: flex;
		// flex-direction: row;
		align-items: center;
		width:100%;
		height:44px;
		border-top:1px #f5f5f5 solid;
		background-color: #fff;
		box-sizing:border-box;
		
		.detail-bottom_icons-input{
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-left:10px;
			padding:0 10px;
			width:100%;
			height:30px;
			border:1px #ddd solid;
			border-radius: 5px;
			
			text{
				font-size: 14px;
				color:#999;
			}
		}
		.detail-bottom_icons{
			display: flex;
			flex-shrink: 0;
			padding: 0 10px;
			
			.detail-bottom_icons-box{
				position: relative;
				display: flex;
				align-items: center;
				justify-content: center;
				width:44px
			}
		}
	}
	
	.popup-wrap{
		background-color: #fff;
		
		.popup-header{
			display: flex;
			justify-content: space-between;
			font-size: 14px;
			color:#666;
			border-bottom: 1px #F5F5F5 solid;
			
			.popup-header_item{
				height:50px;
				line-height:50px;
				padding:0 15px;
			}
		}
		.popup-content{
			width:100%;
			padding:15px;
			box-sizing: border-box;
			
			.popup-textarea{
				width:100%;
				height:200px;
			}
			.popup-count{
				display: flex;
				justify-content: flex-end;
				font-size: 12px;
				color:#999;
			}
		}
	}
</style>
